<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>产品列表页</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>


</head>
<body>
	<!-- 数据列表  start -->
	<!-- 在页面中使用easy ui组件进行界面编程 ,数据表格组件 -->
	<table id="report_dg" title="商品列表" class="easyui-datagrid"
		style="width: 1150px; height: 480px"
		url="${param.request.contextPath}/admin/reportlist" toolbar="#report_toolbar"
		pagination="true" rownumbers="true" fitColumns="true"
		singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<!--  field字段需要与返回数据的属性名一致 -->
				<th field="repId" align="repId">编号</th>
				<th field="score" width="50">综合分数</th>
				<th field="coms" width="50">评语</th>
				<!-- <th field="category.categoryName" width="50">商品分类</th> -->
				<!-- 在列表中显示多表关联数据，需要使用格式化器进行解析数据 -->
				<!-- 如果一个对象的值需要显示多列，field属性的名称不能相同，formatter的方法名字也不能相同 -->
				<th field="name" formatter="teacherFormatter" width="50">班主任</th>
				<th field="stuName" formatter="studentFormatter" width="50">学生姓名</th>
			</tr>
		</thead>
	</table>
	<!-- 工具条组件 -->
	<div id="report_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newReport()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editReport()">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyReport()">删除</a>
	</div>
	<!-- 数据列表 end  -->
	<!-- 新增和修改表单  start -->
	<div id="report_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#report_dlg-buttons">
		<div class="ftitle">学生报告信息管理</div>
		<form id="report_fm"  method="post">
		<div class="fitem">
				<label>学生姓名:</label> <input id="reportStudent"
					name="student.stuId" class="easyui-combobox"
					data-options="valueField:'stuId',textField:'stuName',
					url:'${param.request.contextPath}/student/all'">
			</div>
			<div class="fitem">
				<label>班主任&nbsp;&nbsp;&nbsp;&nbsp;:</label> <input id="reportTeaher"
					name="teacher.tehId" class="easyui-combobox"
					data-options="valueField:'tehId',textField:'name',
					url:'${param.request.contextPath}/teacher/listAll'">
			</div>
			<div class="fitem">
				<label>综合评分:</label> <input name="score"
					class="easyui-textbox" required="true">
			</div>
		<div style="margin-bottom:20px">
            <input name="coms" class="easyui-textbox" label="评语：" labelPosition="top" multiline="true" value="表现良好，继续努力！" style="width:100%;height:120px">
        </div>
		
			
		</form>
	</div>
	<div id="report_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveReport()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#report_dlg').dialog('close')">取消</a>
	</div>
	<!-- 新增和修改表单 end -->
	<script type="text/javascript">
		//easy ui在处理多列数据时，需要使用格式化器解析数据
		
		function teacherFormatter(value, row, index) {
		
			return row.teacher.name;
		}
		function studentFormatter(value, row, index) {
		
			return row.student.stuName;
		}
		function subjectFormatter(value, row, index) {
			//value是传递进来的对象；row是当前行数据，index是第几行数据
	
			return row.subject.subName;
		}
		
		function newReport() {
			$('#report_dlg').dialog('open').dialog('setTitle', '新增报告');
			$('#report_fm').form('clear');
			url = '${pageContext.request.contextPath}/admin/reportadd';
			loadTeacherSuccess(0);
			loadStudentSuccess(0);
			
		}
	

		//下拉列表反选的方法
		function loadStudentSuccess(stuId) {
				var data = $("#reportStudent").combobox("getData");
				console.log(stuId);
				if (data && data.length > 0) {
					if (stuId == 0) {
						$("#reportStudent")
								.combobox("setValue", data[0]['stuId']);
					} else {
						$("#reportStudent").combobox("setValue", stuId);
					}
				}
			}
		function loadTeacherSuccess(tehId) {
			var data = $("#reportTeaher").combobox("getData");
			
			if (data && data.length > 0) {
				if (tehId == 0) {
					$("#reportTeaher")
							.combobox("setValue", data[0]['tehId']);
				} else {
					$("#reportTeaher").combobox("setValue",tehId);
				}
			}
		}
		function saveReport() {
			$('#report_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#report_dlg').dialog('close'); // close the dialog
					$('#report_dg').datagrid('reload'); // reload the user data
				}
			});
		}
		function editReport() {
			$('#report_fm').form('clear');
			var row = $('#report_dg').datagrid('getSelected');
			if (row) {
				$('#report_dlg').dialog('open').dialog('setTitle', '修改报告');
				$('#report_fm').form('load', row);
				url = '${pageContext.request.contextPath}/admin/reportedit?repId='
						+ row.repId;
				loadTeacherSuccess(row.teacher.tehId);
				loadStudentSuccess(row.student.stuId);
			}
		}
		function destroyReport() {
			var row = $('#report_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除报告?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/admin/reportdelete',
														{
															repId : row.repId
														},
														function(result) {
															if (result.success) {
																$('#report_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}
	
	</script>
</body>
</html>